//
//$Id: generic.h 441 2010-04-09 17:27:20Z Oleg.Bulychov $
#pragma once

#include "src/heo/include/lf_endl.h"
#include "src/heo/include/random.h"
#include "src/heo/include/reflection.h"
#include "src/heo/include/solution.h"
#include "src/heo/include/optimization_direction.h"

struct Generic_Config
{
    int         dummy_;

    static char const* get_Name() { return "generic"; }

    template<class V>
    void accept(V& v)
    {
        v(VAR_(dummy),               0);
    }
};
//__________________________________________________________________________________
struct Generic_Problem
{
    int dummy_;

    explicit Generic_Problem():
        dummy_(0)
    {}

    static char const* get_Default_File_Name() { return "foo.bar"; }

    template<class I, class E>
    bool read(I& in, E* env, uniform_random& rnd)
    {
        in >> dummy_;
        return true;
    }
};
//__________________________________________________________________________________
//__________________________________________________________________________________
class Generic_Solution
{
    //DISALLOW_COPY_AND_ASSIGN(Generic_Solution);
public:
    typedef int            TCostType;
    //typedef maximization<TCostType> TDirection;
    typedef minimization<TCostType> TDirection;
protected:
    TCostType    cost_;
    bool         changed_;
public:
    explicit Generic_Solution(): cost_(0), changed_(false)
    {}

    ~Generic_Solution()
    {
    }

    template<class E>
    void init(E* env, uniform_random& rnd)
    {//:NOTE: may be called several times!
    }

    template<class E>
    void generate(E* env, uniform_random& rnd)
    {
        changed_ = true;
    }

    TCostType get_Cost() const
    {
        ASSERT_(!changed_);
        return cost_;
    }

    template<class E>
    void evaluate(E* env, uniform_random& rnd)
    {
        if (!changed_)
            return;
        changed_ = false;
        cost_ = 0;
    }

    void assign(Generic_Solution const& sol)
    {
        changed_ = sol.changed_;
        cost_    = sol.cost_;
    }

    template<class X>
    void copy_To(X& x) const
    {
        x.assign(*this);
    }

	template<class E>
    void print(std::ostream& os, E* env)
    {
        os << lf
            << "cost: " << get_Cost() << lf;
    }

    template<class E>
    static bool read(E* env, std::string const& file_name, Solution_Pool<Generic_Solution>& pool)
    {
        //:see onemax.h for example
        return false;
    }

    template<class E>
    void write(E* env, std::string const& file_name, size_t id, size_t count)
    {
        //:see onemax.h for example
    }

    template<class V>
    void accept(V& v)
    {
        v(cost_);
        v(changed_);
    }
};
//__________________________________________________________________________________

//EOF!
